** Do file to replicate findings in Weisiger and Yarhi-Milo, "Revisiting Reputation: 
** How Past Actions Matter in International Politics".

** This do file first replicates the results from tables one and two in the main text.
** I then replicate results for robustness checks referenced in the main text but not
** reported here.  results.log contains the results from these regressions.  The final
** section reproduces figure 1 using Clarify.

clear all
set more off

log using results.log, replace

use repdata, clear

** Table 1, Model 1

probit mzmidl backdown1 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Model 2

probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Model 3

probit mzmidl backdown1 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if inmid10==1, cluster(dyadid)

** Model 4

probit mzmidl bkdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Model 5

probit mzmidl genrep midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Model 6

xtset dyadid year
xtlogit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, fe


** Table 2, Model 1

probit mzmidl goodrep midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Model 2

probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if ccode1!=ccode_alt, cluster(dyadid)

** Model 3

probit terrmidl backdown_terr1 backdown_nonterr1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor tterr tterr2 tterr3, cluster(dyadid)

** Model 4

use repdata_leaders
probit mzleadmidl backdown1_leader backdown1_newleader midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 [iweight=yrpct], cluster(dyadid)

***************************************************************************************************************************
** In the main text, we note that findings are robust to a variety of changes to variable coding and model specification.
** This section reproduces the regressions necessary to substantiate those claims.  Specifically, we note that the findings
** are robust to the following changes:
** 1) coding backing down in different ways
** 2) limiting the analysis to politically relevant dyads
** 3) controlling for or omitting important historical time periods
** 4) using fatal MIDs instead of all MIDs

** We demonstrate robustness from the baseline model (Table 1, Model 2).
** First, for comparison, the baseline model
probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Next, robustness to changing the way in which a state is coded as acquiring a bad reputation.  We use a total of seven
** different measures that differ in various ways from the main one (which codes a country as backing down if it yielded
** in a MID without fighting, and codes it as acquiring a bad reputation that declines in significance over the subsequent
** ten years).

** Bad reputation from any yielding (including yielding after using force)
probit mzmidl backdown2 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Bad reputation from yielding without escalating to war (hiact<20)
probit mzmidl backdown3 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Bad reputation from yielding or losing in a MID
probit mzmidl backdown4 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Bad reputation from yielding or losing in a MID without escalating to war
probit mzmidl backdown5 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Same as baseline variable, but reputation phases out over 5 years instead of 10
probit mzmidl backdown6 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Same as baseline variable, but reputation phases out over 20 years instead of 10
probit mzmidl backdown7 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Alternate variable analogous to AltRep_it that focuses only on how frequently in recent MIDs the country has backed
** down (i.e. no good reputation)
probit mzmidl badallm midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** For comparison purposes, the same approach looking only at how frequently in recent MIDs the country has fought and
** won (i.e. no bad reputation) -- this analysis compares to Table 2, Model 1.
probit mzmidl goodallm midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** We also use two alternate codings of reputation from the ICB dataset

** First, coding any country that loses a crisis as getting a bad reputation (even if it used force)
probit mzmidl bkdown2 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Second, coding a country that loses a crisis that did not escalate to war as getting a bad reputation
probit mzmidl bkdown3 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

** Limiting the analysis to politically relevant dyads

probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if pol_rel==1, cluster(dyadid)


** Controls for important time periods

gen prewwi=0
replace prewwi=1 if year<1914
gen interwar=0
replace interwar=1 if year>=1914 & year<=1945
gen coldwar=0
replace coldwar=1 if year>1945 & year<1990
gen postcw=0
replace postcw=1 if year>1989

probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor prewwi interwar coldwar t t2 t3, cluster(dyadid)
probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if prewwi!=1, cluster(dyadid)
probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if interwar!=1, cluster(dyadid)
probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if coldwar!=1, cluster(dyadid)
probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3 if postcw!=1, cluster(dyadid)


** Examining fatal MIDs instead of all MIDs
probit mzfatall backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

log close


****************************************************************************************************************************
** Replicating figure 1

use repdata, clear

estsimp probit mzmidl backdown1 midsin10 capratio capsum demlo atopally cntgdumy bothmajr onemajor t t2 t3, cluster(dyadid)

setx median

gen var=""
gen est=.
gen esthi=.
gen estlo=.
gen level=.

local i=1
forvalues n=0(.1)1 {
qui replace var="backdown1" in `i'
qui replace level=`n' in `i'
qui setx backdown1 `n'
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
}

setx backdown1 0

forvalues n=-10/10 {
qui replace var="demlo" in `i'
qui replace level=`n' in `i'
qui setx demlo `n'
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
}
setx demlo median

forvalues n=.5(.01)1.0001 {
qui replace var="capratio" in `i'
qui replace level=`n' in `i'
qui setx capratio `n'
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
}

setx capratio median

forvalues n=1/100 {
qui replace var="capsum" in `i'
qui centile capsum, c(`n')
qui replace level=`n' in `i'
qui setx capsum r(c_1)
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
}

setx capsum median

qui replace var="majors" in `i'
qui replace level=0 in `i'
qui setx (onemajor bothmajr) 0
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
qui replace var="majors" in `i'
qui replace level=1 in `i'
qui setx onemajor 1
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
qui replace var="majors" in `i'
qui replace level=2 in `i'
qui setx bothmajr 1
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1

setx (onemajor bothmajr) median

forvalues n=0/15 {
qui replace var="midsin10" in `i'
qui replace level=`n' in `i'
qui setx midsin10 `n'
qui simqi, genpr(pr)
qui sumqi pr
qui replace esthi=1-r(r2) in `i'
qui replace estlo=1-r(r1) in `i'
qui sum pr
qui replace est=1-r(mean) in `i'
drop pr
local i=`i'+1
}
setx midsin10 median

#del ;
twoway rcap estlo esthi level if var=="backdown1" || scatter est level if var=="backdown1", graphregion(fcolor(white))
legend(off) xtitle("Bad Reputation") name(backdown1, replace) yscale(range(0 .001)) ylabel(0(.0002).001)
;

twoway rcap estlo esthi level if var=="demlo" || scatter est level if var=="demlo", graphregion(fcolor(white))
legend(off) xtitle("Lower Democracy Level") name(demlo, replace) yscale(range(0 .001)) ylabel(0(.0002).001)
;

twoway line esthi level if var=="capratio", lp(dash) lc(gs4) || line estlo level if var=="capratio", lp(dash) lc(gs4)
|| line est level if var=="capratio", lc(black) graphregion(fcolor(white))
legend(off) xtitle("Relative Capabilities") name(capratio, replace) yscale(range(0 .001)) ylabel(0(.0002).001)
;

twoway line esthi level if var=="capsum" & esthi<=.001, lp(dash) lc(gs4) || line estlo level if var=="capsum" & estlo<=.001, lp(dash) lc(gs4)
|| line est level if var=="capsum" & est<=.001, lc(black) graphregion(fcolor(white))
legend(off) xtitle("Capability Sum (Percentile)") name(capsum, replace) yscale(range(0 .001)) ylabel(0(.0002).001)
;

twoway rcap estlo esthi level if var=="majors" || scatter est level if var=="majors", graphregion(fcolor(white))
legend(off) xtitle("Number of Major Powers") name(majors, replace) yscale(range(0 .001)) ylabel(0(.0002).001) 
xlabel(0(1)2)
;

twoway rcap estlo esthi level if var=="midsin10" || scatter est level if var=="midsin10", graphregion(fcolor(white))
legend(off) xtitle("Number of Recent Militarized Disputes") name(midsin10, replace) yscale(range(0 .001)) ylabel(0(.0002).001)
;

graph combine backdown1 demlo capratio capsum majors midsin10, rows(2) graphregion(fcolor(white))
;
